package com.marketlive.system.config;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/*
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/

import org.marketlive.system.config.IConfigurationLeaf;

/**
 * 
 * @inheritDoc
 * @author Huw
 */
public class ConfigurationLeaf extends ConfigurationNode implements IConfigurationLeaf {

    String value;

    /**
     * Logger
     */
    private static Log log = LogFactory.getLog(ConfigurationLeaf.class);

    /**
     * Creates a <code>ConfigurationLeaf</code> with the specified names with
     * the specified value associated with each name.
     * 
     * @param name the name of the leaf
     * @param value the value to associate with the name
     *  
     */
    public ConfigurationLeaf(String name, String value) {
        super(name);
        this.value = value;
        log.debug( "Created leaf: [" + name + ":" + value + "]");
    }

    /**
     * @inheritDoc
     */
    public String getAsString() {
        return value;
    }
    
    /**
     * Sets the value to associate with this leaf.
     * 
     * @param newValue the value to set
     */
    public void setAsString(String newValue) {
        this.value = newValue;
    }

    /**
     * @inheritDoc 
     */
    public int getAsInt() {
        return Integer.parseInt(value);
    }

    /**
     * @inheritDoc
     */
    public boolean getAsBoolean() {
        return Boolean.parseBoolean(value);
    }
    
    /**
     * Returns the associated value as a <code>String</code>.
     * 
     * @return the value as a <code>String</code>
     */
    public String toString() {
    	StringBuffer out = new StringBuffer(100);
    	ConfigurationToString.toStringBuilder(out, this, 0);
    	return out.toString();
    }
}
